var path = require('path')
var webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const ExtractTextPlugin = require("extract-text-webpack-plugin");


module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    // path:path.join(__dirname, 'dist'),
    // publicPath: '/dist',
    filename: 'gs.js',
    // library: 'gsbutton',
    libraryTarget: 'umd',
    umdNamedDefine: true
  },
  module: {
    // loaders: [{ test: /\.scss$/, loader: ExtractTextPlugin.extract('style', "css!sass")},],
    rules: [
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: {// 这里表示不提取的时候，使用什么样的配置来处理css
            loader: 'style-loader',
            options: {
              singleton: true // 表示将页面上的所有css都放到一个style标签内
            }
          },
          use: { loader: 'css-loader' }
        })
      },
      // {
      //   test: /\.scss$/,
      //   use: ExtractTextPlugin.extract({
      //     use: ['css-loader', 'sass-loader']
      //   })
      // },
      {
        test: /\.scss$/,
        use: ['style-loader', 'css-loader', 'sass-loader']
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: /node_modules/
      },

      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('css/index.css'), //提取出来的样式放在style.css文件中
    // new ExtractTextPlugin("style.css")
    // new ExtractTextPlugin("/css/[name].css"),
    new VueLoaderPlugin()

  ],
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json', '.scss']
  },
  devServer: {
    // contentBase: path.resolve(__dirname, "dist"),
    contentBase: path.join(__dirname, 'dist'),
    historyApiFallback: true,
    noInfo: true,
    overlay: true,
    compress: true,
    open: false,
    port: 9999,
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}
